package com.allwees.bs.module.pms.score;

import com.allwees.bs.module.pms.score.model.ScoreFactor;
import lombok.Data;

/**
 * 产品分值参与要素计算逻辑
 *
 * @author yangylsky
 * @since 2020-03-12
 *
 */
@Data
public class DefaultProductScore {
	/**
	 * 爬取位置
	 */
	static final ScoreFactor CRAWL_POS = new ScoreFactor(0.10,
			1.0,
			50.0,
			200.0,
			x -> 0.0,									//0.0
			x -> (50 - x) * (0.85 / 49),			//0.85
			x -> (200 - x) * (0.14 / 150),		//0.14
			x -> x > 1000 ? 0.65 : (1000 - x) * (0.01 / 800)	//0.01
		);

	/**
	 * 成交量
	 */
	static final ScoreFactor TOTAL_SALES = new ScoreFactor(0.15,
			1.0,
			50.0,
			1000.0,
			x -> 0.0,								//0.0
			x -> x * (0.25 / 50),				//0.25
			x -> (x - 50) * (0.5 / 950),		//0.5
			x -> x > 10000 ? 0.25 : (x - 1000) * (0.25 / 9000)	//0.25
		);

	/**
	 * 收藏人数
	 */
	static final ScoreFactor TOTAL_COLLECTIONS = new ScoreFactor(0.05,
			1.0,
			50.0,
			1000.0,
			x -> 0.0,								//0.0
			x -> x * (0.25 / 50),				//0.25
			x -> (x - 50) * (0.5 / 950),		//0.5
			x -> x > 2000 ? 0.25 : (x - 1000) * (0.25 / 1000)	//0.25
		);

	/**
	 * 四星以上（含）好评率
	 */
	static final ScoreFactor TOTAL_GOOD_RATINGS = new ScoreFactor(0.15,
			0.50,
			0.90,
			1.00,
			x -> 0.05,								//0.05
			x -> (x - 0.50) * (0.25 / 0.40),	//0.25
			x -> (x - 0.90) * (0.7 / 0.10),	//0.7
			x -> 0.0									//0.0
		);

	/**
	 * 点击量
	 */
	static final ScoreFactor TOTAL_VIEWS = new ScoreFactor(0.05,
			1.0,
			50.0,
			1000.0,
			x -> 0.0,								//0.0
			x -> x * (0.25 / 50),				//0.25
			x -> (x - 50) * (0.5 / 950),		//0.5
			x -> x > 10000 ? 0.25 : (x - 1000) * (0.25 / 9000)	//0.25
		);

	/**
	 * 上架时间。FactorFun.caculate(Double)传入参数应为 publishDate当前秒数 - 当前日期下一天00:00秒数
	 */
	static final ScoreFactor PUBLISH_DATE = new ScoreFactor(0.5,
			-90 * 24 * 3600.0,	//在当前日期90天之内发布
			-15 * 24 * 3600.0,	//在当前日期15天之内发布
			-1.0,						//当前日期下一天00:00秒数的前一秒
			x -> 0.10,																			//0.10
			x -> (x + 90 * 24 * 3600.0) * (0.25 / (75 * 24 * 3600.0)),		//0.25
			x -> (x + 15 * 24 * 3600.0) * (0.65 / (15 * 24 * 3600.0 - 1)),	//0.65
			x -> 0.0																				//0.0
		);
}
